package com.ztao.kafka.consumer;

import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class ConsumerTest {
//    @KafkaListener(topics = "topic1")
//    public  void  aaa(String msg){
//        System.out.println("收到的消息"+msg);
//    }

    @KafkaListener(topics = "topic1")
    public void receiverMsg(String msg, Acknowledgment acknowledgment) {
        System.out.println("接收到消息" + msg);

        //处理的时候出异常了
        //如果没有异常，执行acknowledge
        //确认提交
        if(true) {
            acknowledgment.acknowledge();
        }else{
            //异常了：  代码异常了 --再次处理  -把他们转发到另一个队列里面去处理
        }

    }
}
